<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" />
    <script>
      const obj = [
        {
          addDate: '2025-04-12 17:29:08',
          isMark: false,
          memberName: null,
          orderId: '7cf2dcf6c3e69dfb988e99c2da0ba6e9',
          orderNo: '20250412001',
          orderType: '30',
          payableAmount: '88.00',
          sailsAchievementAmount: 0,
          sailsAchievementAmountTotal: 0,
          sailsPercentageAmount: 0,
          sailsPercentageAmountTotal: 0,
          workAchievementAmount: 0,
          workAchievementAmountTotal: 0,
          workPercentageAmount: 0,
          workPercentageAmountTotal: 0,
        },
      ]

      function groupFromData(listData) {
        var listGroup = []
        for (let order of listData) {
          order.id = order.orderId
          if (order.addDate && order.addDate.length >= 10) {
            let subToDay = order.addDate.substr(0, 10)
            if (
              listGroup.length > 0 &&
              listGroup[listGroup.length - 1].groupDay == subToDay
            ) {
              // 组中最后一个group的日期，与当前order一致，添加到该group
              listGroup[listGroup.length - 1].listData.push(order)
            } else {
              // 组中没有元素，或者当前日期与组中最后一个元素日期不一样，则新建元素添加到组中
              listGroup.push({
                id: order.orderId,
                groupDay: subToDay,
                groupName: groupName(subToDay),
                listData: [order],
              })
            }
          }
        }
        return listGroup
      }

      function groupName(dateTextToDay) {
        if (!dateTextToDay || dateTextToDay.length < 10) return ''
        let date = new Date(dateTextToDay)
        var weekDay = [
          '星期日',
          '星期一',
          '星期二',
          '星期三',
          '星期四',
          '星期五',
          '星期六',
        ]

        var weekDayText = weekDay[date.getDay()]

        let year = date.getFullYear()
        let month = date.getMonth() + 1
        let day = date.getDate()
        return year + '年' + month + '月' + day + '日' + ' ' + weekDayText
      }

      const listGroup = groupFromData(obj)
      console.log(listGroup, obj)

      const obj2 = [
        {
          addDate: '2025-04-12 17:29:08',
          isMark: false,
          memberName: null,
          orderId: '7cf2dcf6c3e69dfb988e99c2da0ba6e9',
          orderNo: '20250412001',
          orderType: '30',
          payableAmount: '88.00',
          sailsAchievementAmount: 0,
          sailsAchievementAmountTotal: 0,
          sailsPercentageAmount: 0,
          sailsPercentageAmountTotal: 0,
          workAchievementAmount: 0,
          workAchievementAmountTotal: 0,
          workPercentageAmount: 0,
          workPercentageAmountTotal: 0,
        },
      ]
      obj.push(...obj2)

      const uniqueById = [
        ...new Map(obj.map((item) => [item.orderNo, item])).values(),
      ]

      console.log(uniqueById, '@obj')

      const arr = [
        {
          id: '7cf2dcf6c3e69dfb988e99c2da0ba6e9',
          groupDay: '2025-04-12',
          groupName: '2025年4月12日 星期六',
          listData: [
            {
              workPercentageAmountTotal: 0,
              orderType: '30',
              sailsAchievementAmountTotal: 0,
              orderNo: '20250412001',
              orderId: '7cf2dcf6c3e69dfb988e99c2da0ba6e9',
              sailsPercentageAmountTotal: 0,
              workPercentageAmount: 0,
              memberName: null,
              sailsPercentageAmount: 0,
              addDate: '2025-04-12 17:29:08',
              payableAmount: '88.00',
              workAchievementAmountTotal: 0,
              isMark: false,
              sailsAchievementAmount: 0,
              workAchievementAmount: 0,
              id: '7cf2dcf6c3e69dfb988e99c2da0ba6e9',
            },
          ],
        },
      ]
    </script>
  </body>
</html>
